<?php

namespace GanYiInfo\Card;

use GanYiInfo\Contracts\ArrayAble;
use GanYiInfo\Utils\Str;

class DebitCard implements CardInterface, BankCardInterface, ArrayAble
{
    private $mobile;

    private $cardNo;

    private $bankName;

    public function __construct($cardNo, $mobile, $bankName)
    {
        $this->cardNo = $cardNo;
        $this->mobile = $mobile;
        $this->bankName = $bankName;
    }

    /**
     * @param string $mobile
     */
    public function setMobile($mobile)
    {
        $this->mobile = $mobile;
    }

    /**
     * @param string $cardNo
     */
    public function setCardNo($cardNo)
    {
        $this->cardNo = $cardNo;
    }

    /**
     * @param $name
     */
    public function setBankName($name)
    {
        $this->bankName = $name;
    }

    /**
     * @throws \Exception
     */
    public function requireParameters()
    {
        if (Str::checkEmpty($this->cardNo) || !Str::isMobile($this->mobile) || Str::checkEmpty($this->bankName)) {
            throw new \Exception("DebitCard missing require parameter.");
        }
    }

    /**
     * @return array
     */
    public function toArray()
    {
        return [
            "cardNo" => $this->cardNo,
            "mobile" => $this->mobile,
            "bankName" => $this->bankName
        ];
    }
}